package com.simpleframe.domain.setting;

import java.util.HashMap;
import java.util.Map;

import com.simpleframe.exception.SimpleframeException;

public class SettingContext {
	
	//private SettingContext settingContext;
	private static Map<String, String> settings;
	
	static{
		settings = new HashMap<String, String>();
	}

	public static String get(String name){
		return get(name, String.class);
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T get(String name, Class<T> clazz){
		if(settings.containsKey(name)){
			return (T) settings.get(name);
		}
		throw new SimpleframeException("不存在的配置项目 "+name);
	}
	
	public static void remove(String name){
		settings.remove(name);
	}
	
	public static void add(String name, String value){
		if(settings.containsKey(name)){
			throw new SimpleframeException("从复的配置项目 "+name);
		}
		settings.put(name, value);
	}
}
